import processing.core.*;

public class Lappari extends Esine {
	PImage img;
	PImage img2;
	PImage img3;
	float xRotaatio;

	Lappari(PApplet parent, int pts){
		super(parent, pts);
		//		this.arvoRotaatio();
		img = pa.loadImage("textures/Nappaimisto.png");
		img2 = pa.loadImage("textures/Omena.png");
		img3 = pa.loadImage("textures/Naytto4.png");
	}

	public void piirra(){
		super.piirra(); // kaannytaan
		//		pa.translate(0, 40, 0);
		pa.rotateX(this.xRotaatio); //rotaatio
		kansi(img);
		runko(img2, img3);
		super.poppi(); // revert kaannytaan
	}

	//Piirretn lpprin kansi
	void kansi(PImage img){
		//Itse kannen kolmiulotteinen muoto
		//		pa.fill(250);
		pa.box((float)100, (float)1.5, (float)80);

		//Kannen takaosan kuviointi
		pa.pushMatrix();
		pa.beginShape();
		pa.translate((float)0,(float)-0.77,(float)0);
		pa.texture(img2); 
		pa.rotateX(PApplet.PI/2);
		pa.vertex(-50, -40, 0, 0, 0);
		pa.vertex(50, -40, 0, 400, 0);
		pa.vertex(50, 40, 0, 400, 400);
		pa.vertex(-50, 40, 0, 0, 400);
		pa.endShape();
		pa.popMatrix();

		//Nytn kuviointi
		pa.pushMatrix();
		pa.beginShape();
		pa.translate((float)0,(float)0.77,(float)0);
		pa.texture(img3);
		pa.rotateX(PApplet.PI/2);
		pa.vertex(-50, -40, 0, 0, 0);
		pa.vertex(50, -40, 0, 400, 0);
		pa.vertex(50, 40, 0, 400, 400);
		pa.vertex(-50, 40, 0, 0, 400);
		pa.endShape();
		pa.popMatrix();
	}

	//Piirretn lpprin runko-osa
	void runko(PImage img2, PImage img3){
		//Rungon kolmiulotteinen muoto
		//		pa.fill(250);
		pa.translate(0,40,40);
		pa.rotateX(PApplet.PI/2);
		pa.box((float)100, (float)1.5, (float)80);

		//Nppimistn kuviointi
		pa.pushMatrix();
		pa.beginShape();
		pa.translate((float)0,(float)-0.77,(float)0);
		pa.texture(img); 
		pa.rotateX(PApplet.PI/2);
		pa.rotateZ(PApplet.PI);
		pa.vertex(-50, -40, 0, 0, 0);
		pa.vertex(50, -40, 0, 400, 0);
		pa.vertex(50, 40, 0, 400, 400);
		pa.vertex(-50, 40, 0, 0, 400);
		pa.endShape();
		pa.popMatrix();
	}
}